# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: leon

import functools

from coin.exchange.okex.book_builder import BookBuilder
from coin.exchange.okex.kr_rest.product import OkexProduct
from coin.exchange.okex_base.okex_v3_handler_base import OkexSpotV3HandlerBase


class SpotTraits(object):
  @classmethod
  def get_qty_from_trade(cls, trade_msg, timestamp):
    return float(trade_msg['size'])

  @classmethod
  @functools.lru_cache(maxsize=128)
  def get_product_from_instrument_id(cls, instrument_id, timestamp):
    return OkexProduct.FromStrNativeProductV3(instrument_id)


class OkexHandler(OkexSpotV3HandlerBase):
  BookBuilderType = BookBuilder
  TraitsType = SpotTraits
